<?php


namespace App\controllers\admin;


use App\controllers\Base;
use Helper\Config;
use Helper\Output;
use Helper\Mysql;
use Firebase\JWT\JWT;
use Helper\Reg;

class MessageBoard extends Base
{

    public function index($request, $response){

        $page = $request->post['page']?:1;
        $pagesize = $request->post['page_size']?:20;

        $mysql = Mysql::getInstance();

        $list = $mysql->join('customer as c','mb.uid=c.id','left')
                    ->where('platform_id', $request->post['platform_id']?:$this->getUser()->platform_id)
                    ->orderBy('is_read','DESC')
                    ->orderBy('create_at','DESC')
                    ->get('message_board as mb',[($page-1)*$pagesize,$pagesize],'mb.*,c.nick,c.account');

        $total = $mysql->where('platform_id', $request->post['platform_id']?:$this->getUser()->platform_id)->getValue('message_board','count(*)');
        return Output::json(200,['list'=> $list ,'total'=> $total]);

    }




    public function edit($request, $response){

        $id = $request->post['id'];
        unset($request->post['id']);
        $res = Mysql::getInstance()->where('id',$id)->update('message_board',$request->post);
        if($res){
            return Output::json(200);
        }
    }

}